var teamId;
var teamName;
var tmGameId;
$(document).ready(function(){ 
	$('#header').animate({'top':'0px'},400);
	teamId = args.teamId; //取得id的值
	teamName = args.teamName;
	tmGameId = args.tmGameId;
	
	var paraData = {teamId:teamId,tmGameId:tmGameId};
	$.getJSON(path+"/soccer/teamGameAction!selectGameSignup.action",paraData, function(data){
		$("input[name='signupFlag']").each(function() {
			if(data.gameSignup!=undefined&&data.gameSignup.signupFlag!=undefined){
				if($(this).val()==data.gameSignup.signupFlag){
					$(this).attr("checked", true);
				}
			}else{
				if($(this).val()=="1"){
					$(this).attr("checked", true);
				}
			}
		});
		$("input[name='playFlag']").each(function() {
			if(data.gameSignup!=undefined&&data.gameSignup.playFlag!=undefined){
				if($(this).val()==data.gameSignup.playFlag){
					$(this).attr("checked", true);
				}
			}else{
				if($(this).val()=="1"){
					$(this).attr("checked", true);
				}
			}
		});
		if(data==undefined||data.gameSignup==undefined||data.gameSignup.friendQuantity==undefined){
			$("#friendQuantity").val("0");
		}else{
			$("#friendQuantity").val(data.gameSignup.friendQuantity);
		}
		if(data.gameSignup!=undefined){
			$("#remark").val(data.gameSignup.remark);
		}
	});
	$("#submitBtn").click(function(){
		var strMessage;
		var signupFlag=$('input:radio[name="signupFlag"]:checked').val();
		var playFlag=$('input:radio[name="playFlag"]:checked').val();
		
		var friendQuantity=$("#friendQuantity").val();
		var remark=$("#remark").val();
		var postData={teamId:teamId,tmGameId:tmGameId,signupFlag:signupFlag,playFlag:playFlag,friendQuantity:friendQuantity,remark:remark};
		$.post(path+"/soccer/teamGameAction!gameSignUp.action",postData, function(data){
			strMessage = data.strMessage;
			$('#strMessage').text(strMessage);
		},'json');
	});
});
function goBack(){
	window.location.href=path+"/soccer/teamGame.jsp?teamId="+teamId+"&teamName="+teamName;
}
function setPlayFlag(readOnlyFlag,playFlag){
	$("input[name='playFlag']").each(function(){
		if(readOnlyFlag!=true){
			$(this).prop("disabled",false);
		}
		if(playFlag!=undefined&&$(this).val()==playFlag){
			$(this).prop("checked",true);
		}
		if(readOnlyFlag==true){
			$(this).prop("disabled",true);
		}
	});
}
